﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.ApiClient.Model;
using Core.IBusiness.IOrderModule;
using Core.IBusiness.ISDK;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Core.ApiClient.Controllers.MGT
{
    [Route(".v1/MGT/[controller]")]
    [ApiController]
    public class SupplierController : BaseApiController
    {

        public SupplierController(IOrder iOrder, IPay iPay)
            : base(iOrder: iOrder, iPay: iPay)
        {

        }


        /// <summary>
        /// 订单发起付款
        /// [微信]
        /// </summary>
        /// <returns></returns>
        [HttpPost(".aaa")]
        [IgnoreAuthorize]
        public IResult WChatApplyPay()
        {
            if (iProjectInfo.PayAliInfo == null)
            {
                return new ApiResult
                {
                    code = CodeResult.CONFIG_ERROR
                };
            }

            var result = this.iPay.TransferByAccounts("iTool 测试用例", iProjectInfo);

            if (result.IsFinished)
            {
                return new ApiResult
                {
                    code = CodeResult.SUCCESS,
                    date = new
                    {
                        price = result.Date.Key,
                        orderInfo = result.Date.Value
                    }
                };
            }

            return new ApiResult
            {
                code = CodeResult.DATA_NOT_FOUND,
                info = result.Discription
            };

        }

    }
}